package com.huatai.saas.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.huatai.common.api.R;
import com.huatai.common.controller.BaseController;
import com.huatai.saas.dto.AnnouncementInfoDto;
import com.huatai.saas.dto.AnnouncementUpdateDto;
import com.huatai.saas.dto.BaseDto;
import com.huatai.saas.service.AnnouncementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @paogram: nanning-saas
 * @author: zcw
 * @create: 2024-04-25
 * @description: 公告的控制器类
 */
@RestController
@Slf4j
@Api(value = "公告内容管理", tags = "公告内容管理")
@RequestMapping("/announcement")
public class AnnouncementController extends BaseController {

	@Autowired
	private AnnouncementService announcementService;

	@PostMapping("/save")
	@ApiOperation(value = "公告上传", notes = "公告上传")
	@ApiOperationSupport(order = 1)
	public R saveAnnouncement(@RequestBody @Valid AnnouncementInfoDto announcementInfo){
		return R.data(announcementService.saveAnnouncement(announcementInfo));
	}

	@GetMapping("/getList")
	@ApiOperation(value = "公告列表", notes = "公告列表")
	@ApiOperationSupport(order = 2)
	public R getAnnouncement(BaseDto baseDto){
		return R.data(announcementService.getAnnouncementList(baseDto));
	}

	@GetMapping("/getInfo")
	@ApiOperation(value = "查看公告内容", notes = "查看公告内容")
	@ApiOperationSupport(order = 3)
	public R getAnnouncementInfo(@RequestParam Long id){
		return R.data(announcementService.getAnnouncementInfo(id));
	}

	@PostMapping("/del/{id}")
	@ApiOperation(value = "删除公告", notes = "删除公告")
	@ApiOperationSupport(order = 4)
	public R delAnnouncement(@PathVariable Long id){
		return R.data(announcementService.delAnnouncement(id));
	}

	@PostMapping("/update")
	@ApiOperation(value = "修改公告信息", notes = "修改公告信息")
	@ApiOperationSupport(order = 5)
	public R updateAnnouncement(@RequestBody AnnouncementUpdateDto announcementUpdateDto){
		return R.data(announcementService.updateAnnouncement(announcementUpdateDto));
	}
}
